package br.cnpq.webflowah.beans;

import java.io.Serializable;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

/**
 * Class with Service QoS and QoC attributes
 * 
 * @author fred
 * 
 */
public class Metadata implements Serializable {

	private static final long serialVersionUID = 1L;

	// QoS parameters
	public static final String AVALIABILITY = "disponibility";

	public static final String PERFORMANCE = "performance";

	public static final String RESPONSING = "responsing";

	// QoC parameters
	public static final String CORRECTNESS = "correctness";

	public static final String FRESHNESS = "freshness";

	public static final String PRECISION = "precision";

	public static final String RESOLUTION = "resolution";

	private String provider;

	private ServicoSemantico servico;

	private Map<String, QoS> qosMap = null;

	private Map<String, QoC> qocMap = null;

	public Metadata() {
		qocMap = new HashMap<String, QoC>();
		qosMap = new HashMap<String, QoS>();
	}

	public Metadata(ServicoSemantico servico) {
		this();
		this.servico = servico;
	}

	public void insertQualityParameter(AbstractQualityParameter parameter) {
		if (parameter instanceof QoS)
			qosMap.put(parameter.getName(), (QoS) parameter);
		else if (parameter instanceof QoC)
			qocMap.put(parameter.getName(), (QoC) parameter);
	}

	public AbstractQualityParameter getQualityParameter(String parameterName) {
		AbstractQualityParameter aux = qosMap.get(parameterName);
		if (aux == null)
			aux = qocMap.get(parameterName);
		return aux;
	}

	public void updateQualityParameter(String parameterName, String value) {
		if (qosMap.containsKey(parameterName))
			qosMap.get(parameterName).setValue(value);
		else if (qocMap.containsKey(parameterName))// /
			qocMap.get(parameterName).setValue(value);
	}

	public String getProvider() {
		return provider;
	}

	public void setProvider(String provider) {
		this.provider = provider;
	}

	public List<QoC> getQocList() {
		return new LinkedList<QoC>(qocMap.values());
	}

	// public void setQocList(List<QoC> qocList) {
	// this.qocList = qocList;
	// }

	public List<QoS> getQosList() {
		return new LinkedList<QoS>(qosMap.values());
	}

	//
	// public void setQosList(List<QoS> qosList) {
	// this.qosList = qosList;
	// }

	public ServicoSemantico getServico() {
		return servico;
	}

	public void setServico(ServicoSemantico servico) {
		this.servico = servico;
	}

	public int getQuantidadeParametros() {
		return qosMap.size() + qocMap.size();
	}

}
